package com.elephantgreen.util;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * This is a Utility class containing various methods that are needed through
 * out the elephantgreen package.
 * 
 * @author Bishan
 * 
 */
public class Util {

	/**
	 * Constructor private. No instantiation is possible.
	 */
	private Util() {
		// Instantiation is not possible
	}

	public static String getTagValue(String tag, Element element) {
		try {
			NodeList list = element.getElementsByTagName(tag).item(0)
					.getChildNodes();

			Node value = (Node) list.item(0);

			return value.getNodeValue();

		} catch (NullPointerException npe) {
			return "";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

	public static String getAttrValue(String tag, Element element) {

		try {

			return element.getAttribute(tag);

		} catch (NullPointerException npe) {
			return "";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

}
